"""
@author: Sergiy Tsymbalyuk
"""

from pylons.i18n import lazy_ugettext as _

from sqlalchemy import Column
from sqlalchemy.types import Integer, String, Date, Enum, Boolean
from sqlalchemy.dialects.mysql import VARCHAR
from sqlalchemy.orm import mapper

from chowa.model.meta import Base

__all__ = ['Person']

class Person(Base):
    __tablename__ = 'abstract_person'
    __mapper_args__ = {'order_by': 'surname'}
    
    id = Column(Integer, primary_key=True)
    surname = Column(VARCHAR(100, collation='utf8_unicode_ci'), info={'verbose': _('Surname')})
    name = Column(VARCHAR(100, collation='utf8_unicode_ci'), info={'verbose': _('Person|Name')})
    patronymic = Column(VARCHAR(100, collation='utf8_unicode_ci'), info={'verbose': _('Patronymic')})
    born = Column(Date, info={'verbose': _('Born')})
    gender = Column(Enum('M', 'F'), info={'verbose': _('Gender')})
    type = Column(String(30))
    is_insider = Column(Boolean, info={'verbose': _('Is insider')})
    
    __mapper_args__ = {'polymorphic_on': type}
    
    def __unicode__(self):
        return u'%s %s %s' % (self.surname,
                              self.name,
                              self.patronymic)

    def short_name(self):
        return u'%s %s.%s.' % (self.surname,
                               self.name[0],
                               self.patronymic[0])
    
def person_full_name():
    return (Person.surname, Person.name, Person.patronymic)
